<script setup lang="ts">
import { formattedDate } from "@/utils/formatDate.ts";
import { Delete, Edit, InfoFilled } from "@element-plus/icons-vue";
import Dialog from "@/view/Distribute/Coach/dialog.vue";
import useCoach from "@/view/Distribute/Coach/utils/hook.ts";

const {
  dialog,
  coachStore,
  handleAdd,
  EditCoach,
  deleteCoach
} = useCoach()
</script>

<template>
  <el-card class="box-card">
    <div class="card-coach-title">
      <el-button type="primary" @click="handleAdd">添加教练</el-button>
    </div>
    <div class="card-coach-table">
      <el-table
        border
        class="el-table-box"
        ref="multipleTableRef"
        :data="coachStore.coachList"
        style="width: 100%"
      >
        <el-table-column label="#" width="60" align="center" type="index"/>
        <el-table-column prop="name" align="center" label="名称" width="80"/>
        <el-table-column prop="age" align="center" label="年龄" width="60"/>
        <el-table-column prop="phone" align="center" label="手机号" width="120"/>
        <el-table-column prop="scope" align="center" label="评分" width="60"/>
        <el-table-column prop="salary" align="center" label="薪资" width="80"/>
        <el-table-column prop="address" align="center" label="地址" width="120"/>
        <el-table-column align="center" label="描述" width="160">
          <template #default="{row}">
            <p class="limit-row">
              {{ row.desc }}
            </p>
          </template>
        </el-table-column>
        <el-table-column align="center" label="入职时间" width="120">
          <template #default="{row}">
            {{ formattedDate(row.createdAt) }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="控制">
          <template #default="{row}">
            <div class="operator-btn">
              <el-button type="primary" size="default" :icon="Edit as any" @click="EditCoach(row)" circle/>
              <el-popconfirm
                width="200"
                @confirm="deleteCoach(row._id)"
                confirm-button-text="确定"
                cancel-button-text="取消"
                :icon="InfoFilled as any"
                icon-color="#f36b6c"
                title="您确定删除此设备吗?"
              >
                <template #reference>
                  <el-button type="danger" size="default" :icon="Delete as any" circle/>
                </template>
              </el-popconfirm>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </el-card>
  <Dialog ref="dialog"/>
</template>

<style scoped lang="scss">
.box-card {
  padding: 0 50px;

  .card-coach-title {
    height: 35px;
    display: flex;
    justify-content: flex-end;
  }

  .card-coach-table {
    margin-top: 20px;

    .el-table-box {
      height: calc(90vh - 140px);

      .el-table__cell {
        position: static !important; // 解决el-image 和 el-table冲突层级冲突问题
      }
    }

    .coach-desc {
      display: -webkit-box; /*弹性伸缩盒子*/
      -webkit-box-orient: vertical; /*垂直排列*/
      line-height: 20px;
      -webkit-line-clamp: 1;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}

.limit-row {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
}

.dialog-item {
  display: flex;
  flex-direction: row;
  height: 30px;
  align-items: center;

  p {
    margin-left: 12px;
  }
}
</style>
